#pragma once

#include "Poller.h"
#include "Timestamp.h"

#include <vector>
#include <sys/epoll.h>

/**
 epoll 的使用
 epoll_create
 epoll_ctl add / modify / delete
 epoll_wait
 */
class EPollPoller : public Poller 
{
public:
  EPollPoller(EventLoop* loop);
  ~EPollPoller() override;
  // 重写基类的抽象方法
  Timestamp poll(int timeoutMs, ChannelList* activeChannels) override;
  void updateChannel(Channel* channel) override;
  void removeChannel(Channel* channel) override;
private:
  static const int kInitEventListSize = 16;
  // 填写活跃的 channel 数组
  void fillActiveChannels(int numEvents, ChannelList *activeChannel);
  void update(int operation, Channel* channel);
private:
  using EventList = std::vector<epoll_event>;

  int m_epollFd;
  EventList m_events;
};